<template>
  <s-tabbar :value="tabIndex" :list="version == '1' ? tabList2 : tabList" :border="border" :shadow="shadow"
    :background="customColor ? '#333333' : ''" active-color="#FB7C22" :border-color="customColor ? '#333333' : ''"
    :mid-button-icon-style="{
      background: 'var(--v-linear)',
      borderRadius: '50%',
      fontSize: '40rpx',
      width: '70rpx',
      height: '70rpx',
      color: 'white',
    }" :mid-button-circle-style="{
  boxShadow: ' rgba(50, 50, 105, 0.15) 0px -2px 5px 0px, rgba(0, 0, 0, 0.05) 0px -1px 1px 0px',
  background: '#fff'
}" @change="onChange" />
</template>
<script>
export default {
  props: {
    version: {
      default: 0
    },
    tabIndex: {
      type: Number,
      default: 0,
    },
  },
  data() {
    return {
      // 原始tabbar数据（完全未修改）
      midButton: true,
      border: true,
      shadow: false,
      customColor: false,
      customHome: false,
      beforeChange: false,
      tabList: [
        {
          text: "首页",
          iconimg: "http://ziyuanstatic.oss-cn-beijing.aliyuncs.com/static/iconimgs/1.png",
          activeIconimg: "http://ziyuanstatic.oss-cn-beijing.aliyuncs.com/static/iconimgs/1s.png",
          link: "/pages/index/index",
        },
        {
          text: "素材管理",
          iconimg: "http://ziyuanstatic.oss-cn-beijing.aliyuncs.com/static/iconimgs/2.png",
          activeIconimg: "http://ziyuanstatic.oss-cn-beijing.aliyuncs.com/static/iconimgs/2s.png",
          link: "/pages/material/index",
        },
        {
          text: "新建",
          iconimg: "http://ziyuanstatic.oss-cn-beijing.aliyuncs.com/static/iconimgs/add.png",
          midButton: true,
          link: "/pages/order/index",
        },
        {
          text: "档期管理",
          iconimg: "http://ziyuanstatic.oss-cn-beijing.aliyuncs.com/static/iconimgs/3.png",
          activeIconimg: "http://ziyuanstatic.oss-cn-beijing.aliyuncs.com/static/iconimgs/3s.png",
          link: "/pages/calendar/index",
        },
        {
          text: "我的",
          iconimg: "http://ziyuanstatic.oss-cn-beijing.aliyuncs.com/static/iconimgs/4.png",
          activeIconimg: "http://ziyuanstatic.oss-cn-beijing.aliyuncs.com/static/iconimgs/4s.png",
          link: "/pages/user/index",
        },
      ],
      tabList2: [
        {
          text: "首页",
          iconimg: "http://ziyuanstatic.oss-cn-beijing.aliyuncs.com/static/iconimgs/1.png",
          activeIconimg: "http://ziyuanstatic.oss-cn-beijing.aliyuncs.com/static/iconimgs/1s.png",
          link: "/pages/index/index",
        },
        {
          text: "营业额统计",
          iconimg: "http://ziyuanstatic.oss-cn-beijing.aliyuncs.com/static/iconimgs/2.png",
          activeIconimg: "http://ziyuanstatic.oss-cn-beijing.aliyuncs.com/static/iconimgs/2s.png",
          link: "/pages/extra/stats/index",
        },
        {
          text: "新建",
          iconimg: "http://ziyuanstatic.oss-cn-beijing.aliyuncs.com/static/iconimgs/add.png",
          midButton: true,
          link: "/pages/order/index",
        },
        {
          text: "档期管理",
          iconimg: "http://ziyuanstatic.oss-cn-beijing.aliyuncs.com/static/iconimgs/3.png",
          activeIconimg: "http://ziyuanstatic.oss-cn-beijing.aliyuncs.com/static/iconimgs/3s.png",
          link: "/pages/calendar/index",
        },
        {
          text: "我的",
          iconimg: "http://ziyuanstatic.oss-cn-beijing.aliyuncs.com/static/iconimgs/4.png",
          activeIconimg: "http://ziyuanstatic.oss-cn-beijing.aliyuncs.com/static/iconimgs/4s.png",
          link: "/pages/user/index",
        },
      ],
    };
  },
  mounted() {
    // this.version = uni.getStorageSync('version')
    // if (this.version == '1') {
    //   this.tabList[1].text = "营业额统计"
    //   this.tabList[1].link = "/pages/extra/stats/index"
    // }
    // console.log(uni.getStorageSync('version'))
    // console.log("子组件 onLoad 执行");
  },
  methods: {
    onChange(index) {
      let arrays = this.version == 1 ? this.tabList2 : this.tabList
      console.log(index)
      const item = arrays[index];
      if (item.midButton) {
        // 中间按钮特殊处理，直接跳转到对应页面
        console.log(item.link)
        uni.navigateTo({
          url: item.link
        });
      } else {
        console.log(this.version)

        if (this.version == 1) {
          if (index == 1) {
            uni.navigateTo({
              url: '/pages/extra/stats/index'
            });
          } else {
            this.$emit("tabBarChange", item.link);
          }

        } else {
          console.log(item.link)
          this.$emit("tabBarChange", item.link);
        }

      }
    },
  },
};
</script>
<style></style>